package com.example.controller;

import com.example.common.Result;
import com.example.service.OpinionAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 舆情分析控制器
 */
@RestController
@RequestMapping("/api/opinion")
@CrossOrigin
public class OpinionAnalysisController {

    @Autowired
    private OpinionAnalysisService opinionAnalysisService;

    /**
     * 获取热词统计数据
     */
    @GetMapping("/hot-words/stats")
    public Result getHotWordsStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getHotWordsStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取热词统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取热词列表
     */
    @GetMapping("/hot-words")
    public Result getHotWords(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getHotWords(params));
        } catch (Exception e) {
            return Result.error("获取热词列表失败: " + e.getMessage());
        }
    }

    /**
     * 获取平台统计数据
     */
    @GetMapping("/platform/stats")
    public Result getPlatformStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getPlatformStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取平台统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取平台详情数据
     */
    @GetMapping("/platform/details")
    public Result getPlatformDetails(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getPlatformDetails(params));
        } catch (Exception e) {
            return Result.error("获取平台详情失败: " + e.getMessage());
        }
    }

    /**
     * 获取平台图表数据
     */
    @GetMapping("/platform/charts")
    public Result getPlatformCharts(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getPlatformCharts(params));
        } catch (Exception e) {
            return Result.error("获取平台图表数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取文章统计数据
     */
    @GetMapping("/articles/stats")
    public Result getArticleStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getArticleStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取文章统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取文章列表
     */
    @GetMapping("/articles")
    public Result getArticles(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getArticles(params));
        } catch (Exception e) {
            return Result.error("获取文章列表失败: " + e.getMessage());
        }
    }

    /**
     * 获取文章图表数据
     */
    @GetMapping("/articles/charts")
    public Result getArticleCharts(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getArticleCharts(params));
        } catch (Exception e) {
            return Result.error("获取文章图表数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取IP统计数据
     */
    @GetMapping("/ip/stats")
    public Result getIPStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getIPStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取IP统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取IP图表数据
     */
    @GetMapping("/ip/charts")
    public Result getIPCharts(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getIPCharts(params));
        } catch (Exception e) {
            return Result.error("获取IP图表数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取评论统计数据
     */
    @GetMapping("/comments/stats")
    public Result getCommentStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getCommentStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取评论统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取评论列表
     */
    @GetMapping("/comments")
    public Result getComments(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getComments(params));
        } catch (Exception e) {
            return Result.error("获取评论列表失败: " + e.getMessage());
        }
    }

    /**
     * 获取评论图表数据
     */
    @GetMapping("/comments/charts")
    public Result getCommentCharts(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getCommentCharts(params));
        } catch (Exception e) {
            return Result.error("获取评论图表数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取舆情统计数据
     */
    @GetMapping("/opinion/stats")
    public Result getOpinionStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getOpinionStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取舆情统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取舆情报告列表
     */
    @GetMapping("/opinion/reports")
    public Result getOpinionReports(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getOpinionReports(params));
        } catch (Exception e) {
            return Result.error("获取舆情报告列表失败: " + e.getMessage());
        }
    }

    /**
     * 获取舆情图表数据
     */
    @GetMapping("/opinion/charts")
    public Result getOpinionCharts(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getOpinionCharts(params));
        } catch (Exception e) {
            return Result.error("获取舆情图表数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取词云统计数据
     */
    @GetMapping("/wordcloud/stats")
    public Result getWordCloudStats(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> stats = opinionAnalysisService.getWordCloudStats(params);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取词云统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取词云数据
     */
    @GetMapping("/wordcloud/data")
    public Result getWordCloudData(@RequestParam Map<String, Object> params) {
        try {
            return Result.success(opinionAnalysisService.getWordCloudData(params));
        } catch (Exception e) {
            return Result.error("获取词云数据失败: " + e.getMessage());
        }
    }
} 